/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common.h;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.c.a;
import com.qihoo.gamecenter.sdk.common.i.c;
import com.qihoo.gamecenter.sdk.common.i.s;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

public abstract class d extends AsyncTask {
    private a b;
    private a c;
    private WeakReference d;
    private boolean e;
    private Context f;
    protected String a = null;

    public d(Context paramContext, a parama, boolean paramBoolean) {
        this.d = new WeakReference(paramContext);
        this.c = parama;
        this.e = paramBoolean;
        this.b = a.a(paramContext);
        this.f = paramContext;
    }

    private Context c() {
        if (this.d != null)
            return ((Context) this.d.get());
        return null;
    }

    protected String a(String[] paramArrayOfString) {
        String str = null;
        Context localContext = c();
        if (localContext != null)
            if (this.e) {
                str = a();
                ArrayList localArrayList = a(b(localContext, paramArrayOfString));
                if ((!(TextUtils.isEmpty(str))) && (localArrayList != null))
                    return this.b.a(str, localArrayList, this.a);
            }
            else {
                str = a(localContext, paramArrayOfString);
                if (!(TextUtils.isEmpty(str)))
                    return this.b.b(str, this.a);
            }
        try {
            return new JSONObject().put("error_code", 0).put("error_msg", "Context or URL or Post Params ERROR")
                    .toString();
        } catch (JSONException localJSONException) {
            c.b("HttpAsyncTask", new Object[] { localJSONException.toString() });
        }
        return null;
    }

    protected void onCancelled() {
        c.a("HttpAsyncTask", new Object[] { "onCancelled=" });
        this.c = null;
        super.onCancelled();
    }

    protected void a(String paramString) {
        c.a("HttpAsyncTask", new Object[] { "onPostExecute=", paramString });
        if (isCancelled())
            return;
        try {
            JSONObject localJSONObject1 = new JSONObject(paramString);
            int i = localJSONObject1.getInt("error_code");
            String str = localJSONObject1.optString("error_msg");
            a(c(), i, str);
            JSONObject localJSONObject2 = localJSONObject1.optJSONObject("content");
            if (localJSONObject2 != null) {
                int j = localJSONObject2.optInt("error_code", -1);
                if ((j == 4010201) || (j == 4010202)) {
                    Intent localIntent = new Intent();
                    localIntent.putExtra("action_code", j);
                    localIntent.setFlags(536870912);
                    localIntent.setClassName(this.f, "com.qihoo.gamecenter.sdk.activity.ContainerActivity");
                    this.f.startActivity(localIntent);
                    return;
                }
                a(i, str, a(localJSONObject2));
            }
            else {
                a(i, str, null);
            }
            return;
        } catch (JSONException localJSONException) {
            c.b("HttpAsyncTask", new Object[] { localJSONException.toString() });
            a(0, "JSON PARSE ERROR!!!", null);
            return;
        }
    }

    private void a(int paramInt, String paramString, Object paramObject) {
        if (this.c == null)
            return;
        this.c.a(paramInt, paramString, paramObject);
        this.c = null;
    }

    private void a(Context paramContext, int paramInt, String paramString) {
        if ((paramContext == null) || (paramInt == 0) || (TextUtils.isEmpty(paramString)))
            return;
        s.a(paramContext, paramInt, paramString, false);
    }

    private ArrayList a(Map paramMap) {
        if (paramMap == null)
            return null;
        ArrayList localArrayList = new ArrayList();
        Iterator localIterator = paramMap.entrySet().iterator();
        while (localIterator.hasNext()) {
            Map.Entry localEntry = (Map.Entry) localIterator.next();
            if (localEntry != null) {
                String str1 = (String) localEntry.getKey();
                String str2 = (String) localEntry.getValue();
                if ((!(TextUtils.isEmpty(str1))) && (!(TextUtils.isEmpty(str2))))
                    localArrayList.add(new BasicNameValuePair(str1, str2));
            }
        }
        return localArrayList;
    }

    protected String a(int paramInt, String[] paramArrayOfString) {
        if (paramArrayOfString != null)
            return (((paramArrayOfString.length > paramInt) && (paramInt >= 0)) ? paramArrayOfString[paramInt] : null);
        return null;
    }

    protected abstract String a(Context paramContext, String[] paramArrayOfString);

    protected abstract String a();

    protected abstract Map b(Context paramContext, String[] paramArrayOfString);

    protected abstract Object a(JSONObject paramJSONObject);

    protected boolean b() {
        return false;
    }

    public static abstract interface a {
        public abstract void a(int paramInt, String paramString, Object paramObject);
    }
}